IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[or_MatchMentorMentee]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.[or_MatchMentorMentee]
Go

CREATE  PROCEDURE  dbo.[or_MatchMentorMentee]  
	@MenteeID int
AS


select mentorUser.MeMaUserID, COUNT(*) MentorMatchScore 
INTO #temp
from UserMentorTag mentee
JOIN UserMentorTag mentor ON mentee.MentorMatchTagID = mentor.MentorMatchTagID 
JOIN MeMaUser mentorUser ON mentor.MeMaUserID = mentorUser.MeMaUserID

WHERE mentee.MeMaUserID =  @MenteeID
AND mentorUser.UserTypeID = 2
GROUP BY mentorUser.MeMaUserID 
order by COUNT(*)

SELECT
	m.MeMaUserID	 ,
	UserTypeID	 ,				
	FirstName	 ,
	LastName	 ,
	Email		 ,
	Password	 ,
	IsActive	 ,
    LastModDate  ,
    CreatedDate       
    FROM MeMaUser m  join  #temp t on t.MeMaUserID = m.MeMaUserID

